﻿using System;
using System.Diagnostics;
using System.IO;
using log4net;

namespace AiFrame.InterfaceLib.Logs
{ 
    /// <summary>
    /// Central log handler
    /// </summary>
    public class LogHandler
    {
        private static ILog _logger = null;
        private static object _loggerLock = new object();

        public static ILog GetLogger()
        {
            lock (_loggerLock)
            {
                if (_logger == null)
                {
                    // get call stack
                    StackTrace stackTrace = new StackTrace();

                    FileInfo fileInfo = new FileInfo("log4net.config");
                    log4net.Config.XmlConfigurator.Configure(fileInfo);
                    _logger = log4net.LogManager.GetLogger(stackTrace.GetFrame(1).GetMethod().DeclaringType);
                }

                return _logger;
            }
        }

    }
}
